# candidates = [2,3,6,7]
# target = 7

# candidates = [2,3,5]
# target = 8

# candidates = [2]
# target = 1

# candidates = [1]
# target = 1

candidates = [1]
target = 2
def dfs(candidates,target,res,path,sum,index):
    #出口条件
    if sum>=target:
        if sum==target:
            res.append(path[:])
        else:
            return None
    for i in range(index,len(candidates)):
        path.append(candidates[i])
        dfs(candidates,target,res,path,sum+candidates[i],i)
        path.pop()

def combinationSum(candidates, target):
    #保存路径用的
    path=[]
    #保存结果
    res=[]
    dfs(candidates,target,res,path,0,0)
    return res

print(combinationSum(candidates,target))